package com.yuncheng.spcyApi.controller;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.bo.PartyHyCjryParamBo;
import com.yuncheng.spcyApi.partyService.PartyHyService;
import com.yuncheng.spcyApi.constant.common.SpcyCommonConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.common.StartEndStringVo;
import com.yuncheng.spcyApi.vo.sqsx.HyPrintVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "党务-会议管理")
@RestController
@RequestMapping("/api/spzx-spcy/partyHy")
public class PartyHyController {

    @Resource
    private PartyHyService partyHyService;

    /************************************[ 会议计划 ]**************************************************************************/

    @Log(title = "党务会议计划-分页查询")
    @ApiOperation(value = "党务会议计划-分页查询")
    @GetMapping(value = "queryHyjhPageList")
    public HttpResult<?> queryHyjhPageList(PartyRsDwhyjh query, PageVo pageVo, OrderItemVo orderItemVo) {
        return partyHyService.queryHyjhPageList(query,pageVo.getPageNo(),pageVo.getPageSize(),orderItemVo);
    }

    @Log(title = "党务会议计划-添加/修改")
    @ApiOperation(value = "党务会议计划-添加/修改")
    @PostMapping(value = "saveHyjh")
    public HttpResult saveHyjh(@RequestBody PartyRsDwhyjh bean) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

        if (StringUtils.isNotBlank(bean.getId())){
            bean = partyHyService.updateHyjh((HashMap<String, String>) BeanUtils.describe(bean));
        }else {
            bean = partyHyService.addHyjh(bean);
        }

        return HttpResultVo.HttpResultSave(bean);
    }

    @Log(title = "党务会议计划-删除")
    @ApiOperation(value = "党务会议计划-删除")
    @DeleteMapping(value = "deleteHyjh")
        public HttpResult deleteHyjh(@RequestParam(value = "id",defaultValue = "")String id){
        partyHyService.deleteHyjh(id);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "查询会议计划参加人员-根据会议计划id")
    @ApiOperation(value = "查询会议计划参加人员-根据会议计划id")
    @GetMapping(value = "queryHyjhCjryList")
    public HttpResult queryHyjhCjryList(@RequestParam(value = "fhyid",defaultValue = "")String fhyid){
        List<PartyRsDwhyjhcjry> list = partyHyService.queryHyjhCjryList(fhyid);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "会议计划参加人员-添加")
    @ApiOperation(value = "会议计划参加人员-添加")
    @PostMapping(value = "addHyjhCjry")
    public HttpResult addHyjhCjry(@RequestBody PartyHyCjryParamBo paramBo){
        partyHyService.addHyjhCjry(paramBo);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "会议计划参加人员-删除")
    @ApiOperation(value = "会议计划参加人员-删除")
    @DeleteMapping(value = "deleteHjjhCjry")
    public HttpResult deleteHjjhCjry(@RequestParam(value = "id",defaultValue = "")String id){
        partyHyService.deleteHjjhCjry(id);

        return HttpResult.ok("删除成功");
    }

    /************************************[ 会议记录]**************************************************************************/

    @Log(title = "党务会议管理-分页查询")
    @ApiOperation(value = "党务会议管理-分页查询")
    @GetMapping(value = "queryHyjlPageList")
    public HttpResult<?> queryHyjlPageList(PartyRsDwhyjl query, StartEndStringVo timeVo, PageVo pageVo, OrderItemVo orderItemVo) {
        return partyHyService.queryHyjlPageList(query,timeVo,pageVo.getPageNo(),pageVo.getPageSize(),orderItemVo);
    }

    @Log(title = "党务会议办理-分页查询")
    @ApiOperation(value = "党务会议办理-分页查询")
    @GetMapping(value = "queryHyjlBlPageList")
    public HttpResult<?> queryHyjlBlPageList(PartyRsDwhyjl query, StartEndStringVo timeVo,PageVo pageVo,OrderItemVo orderItemVo) {
        if (StringUtils.isBlank(query.getFhyzt())){
            query.setFhyzt(SpcyCommonConstant.HYJL_HYZT_WKS);
        }
        query.setFhyjlry(GetCurrentUserUtils.getCurrentUserId());
        return partyHyService.queryHyjlPageList(query,timeVo,pageVo.getPageNo(),pageVo.getPageSize(),orderItemVo);
    }

    @Log(title = "党务会议个人记录-分页查询")
    @ApiOperation(value = "党务会议个人记录-分页查询")
    @GetMapping(value = "queryMyHyjlPageList")
    public HttpResult<?> queryMyHyjlPageList(PartyRsDwhyjl query, StartEndStringVo timeVo,PageVo pageVo,OrderItemVo orderItemVo) {
        return partyHyService.queryMyHyjlPageList(query,timeVo,pageVo.getPageNo(),pageVo.getPageSize(),orderItemVo);
    }

    @Log(title = "党务会议记录-添加/修改")
    @ApiOperation(value = "党务会议记录-添加/修改")
    @PostMapping(value = "saveHyjl")
    public HttpResult saveHyjl(@RequestBody PartyRsDwhyjl bean) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

        if (StringUtils.isNotBlank(bean.getId())){
            bean = partyHyService.updateHyjl((HashMap<String, String>) BeanUtils.describe(bean));
        }else {
            bean = partyHyService.addHyjl(bean);
        }

        return HttpResultVo.HttpResultSave(bean);
    }

    @Log(title = "党务会议记录-删除")
    @ApiOperation(value = "党务会议记录-删除")
    @DeleteMapping(value = "deleteHyjl")
    public HttpResult deleteHyjl(@RequestParam(value = "id",defaultValue = "")String id){
        partyHyService.deleteHyjl(id);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "会议记录详情")
    @ApiOperation(value = "会议记录详情")
    @GetMapping(value = "queryHyxqById")
    public HttpResult queryHyxqById(@RequestParam(value = "id",defaultValue = "")String id){
        Map map = partyHyService.queryHyxqById(id);

        return HttpResult.ok(map);
    }

    @Log(title = "提交会议记录")
    @ApiOperation(value = "提交会议记录")
    @PostMapping(value = "completionHyjl")
    public HttpResult completionHyjl(@RequestBody PartyRsDwhyjl hy){
        partyHyService.completionHyjl(hy.getId(), hy.getFhynr(), hy);

        return HttpResult.ok("提交成功");
    }

    @Log(title = "查询会议记录参加人员-根据会议id")
    @ApiOperation(value = "查询会议记录参加人员-根据会议id")
    @GetMapping(value = "queryHyjlCjryList")
    public HttpResult queryHyjlCjryList(@RequestParam(value = "fhyid",defaultValue = "")String fhyid){
        List<PartyRsDwhycjry> list = partyHyService.queryHyjlCjryList(fhyid);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "查询会议记录请假人员-根据会议id")
    @ApiOperation(value = "查询会议记录请假人员-根据会议id")
    @GetMapping(value = "queryHyjlQjryList")
    public HttpResult queryHyjlQjryList(@RequestParam(value = "fhyid",defaultValue = "")String fhyid){
        List<PartyRsDwhycjry> list = partyHyService.queryHyjlQjryList(fhyid);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "会议记录参加人员-添加")
    @ApiOperation(value = "会议记录参加人员-添加")
    @PostMapping(value = "addHyjlCjry")
    public HttpResult addHyjlCjry(@RequestBody PartyHyCjryParamBo paramBo){
        partyHyService.addHyjlCjry(paramBo);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "会议记录请假人员-添加")
    @ApiOperation(value = "会议记录请假人员-添加")
    @PostMapping(value = "addHyjlQjry")
    public HttpResult addHyjlQjry(@RequestBody PartyHyCjryParamBo paramBo){
        partyHyService.addHyjlQjry(paramBo);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "会议记录参加人员-删除")
    @ApiOperation(value = "会议记录参加人员-删除")
    @DeleteMapping(value = "deleteHjjlCjry")
    public HttpResult deleteHjjlCjry(@RequestParam(value = "id",defaultValue = "")String id){
        partyHyService.deleteHjjlCjry(id);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "打印列表数据")
    @ApiOperation(value = "打印列表数据")
    @PostMapping(value = "queryPrintDataList")
    public HttpResult queryPrintDataList(@RequestBody HyPrintVo printVo){
        List<Map> mapList = partyHyService.queryPrintDataList(printVo);

        return HttpResult.ok(mapList);
    }

    @Log(title = "附件-上传")
    @ApiOperation(value = "附件-上传")
    @ApiImplicitParam(name = "id",value = "当前数据id")
    @PostMapping(value = "/uploadFile")
    public HttpResult<?> uploadFile(@RequestPart("file") MultipartFile[] uploadFile,
                                    @RequestParam(value = "id",defaultValue = "") String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("上传失败，数据参数为空！");
        }

        partyHyService.uploadFile(uploadFile,id);

        return HttpResult.ok("上传成功");
    }

}
